<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div id="box">
    {{text}}
    请输入值:
    <input type="text" v-model.number="value" name="" @keyup.enter="keyup" id="">
    <br>
    数组:{{arr}}
    <br>
    和:{{sum}}
  </div>

  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.js"></script>

  <script>

    new Vue({
      el: '#box',
      data: {
        text: 'hello Vue',
        arr: [1, 3, 5, 7, 9],
        value: ''
      },
      methods: {
        keyup() {
          this.arr.push(this.value)
          this.value = ''
        }

      },
      //计算属性
      computed: {
        //函数,并且函数有返回值
        sum() {
          return this.arr.reduce((sum, next) => sum + next)
        }
      }
    })

  </script>

</body>

</html>